clear all
set more off

do "set_path.do"

***** I. SUMMARY STATS BY CURRENCY *****

capture drop program summstats
program define summstats
	args dvar

	xtset panel_id date
	la var con "Mean"
	eststo clear

	local curr AUD
	eststo modall:  newey `dvar' con if tenor == "5y" & currency == "`curr'" , lag(91) force nocons
	eststo mod0006: newey `dvar' con if tenor == "5y" & currency == "`curr'" & year(date) >= 2000 & year(date) <= 2006, lag(91) force nocons
	eststo mod1020: newey `dvar' con if tenor == "5y" & currency == "`curr'" & year(date) >= 2010 & year(date) <= 2020, lag(91) force nocons
	eststo mod2125: newey `dvar' con if tenor == "5y" & currency == "`curr'" & year(date) >= 2021, lag(91) force nocons

	esttab modall mod0006 mod1020 mod2125 using "${outdir}tables/summstats_`dvar'_v2.tex", replace b(1) se(1) stats(N, fmt(%9.0fc)) label nonumbers mtitles("Full Sample" "2000-2006" "2010-2020" "2021-2025") nolines posthead("\midrule \multicolumn{@span}{l}{\textbf{`curr'}} \\") nogaps prehead("\begin{tabular}{l*{@M}{c}} \midrule") prefoot("") postfoot("")
	
	foreach curr in CAD CHF DKK EUR GBP JPY NOK NZD SEK {
		eststo modall:  newey `dvar' con if tenor == "5y" & currency == "`curr'" , lag(91) force nocons
		eststo mod0006: newey `dvar' con if tenor == "5y" & currency == "`curr'" & year(date) >= 2000 & year(date) <= 2006, lag(91) force nocons
		eststo mod1020: newey `dvar' con if tenor == "5y" & currency == "`curr'" & year(date) >= 2010 & year(date) <= 2020, lag(91) force nocons
		eststo mod2125: newey `dvar' con if tenor == "5y" & currency == "`curr'" & year(date) >= 2021, lag(91) force nocons

		esttab modall mod0006 mod1020 mod2125 using "${outdir}tables/summstats_`dvar'_v2.tex", append b(1) se(1) stats(N, fmt(%9.0fc)) label nonumbers nomtitle nolines nogaps posthead("\multicolumn{@span}{l}{\textbf{`curr'}} \\")	prehead("[1em]") prefoot("") postfoot("")
	}
	
	xtset panel_id bdate
	eststo all: 	xtscc `dvar' con if group == "g10" & tenor == "5y" , lag(91) nocons
	eststo all0006: xtscc `dvar' con if group == "g10" & tenor == "5y"  & year(date) >= 2000 & year(date) <= 2006, lag(91) nocons
	eststo all1020: xtscc `dvar' con if group == "g10" & tenor == "5y"  & year(date) >= 2010 & year(date) <= 2020, lag(91) nocons
	eststo all2125: xtscc `dvar' con if group == "g10" & tenor == "5y"  & year(date) >= 2021, lag(91) nocons

	esttab all all0006 all1020 all2125 using "${outdir}tables/summstats_`dvar'_v2.tex", append b(1) se(1) stats(N, fmt(%9.0fc)) label nonumbers nomtitle nolines nogaps posthead("\multicolumn{@span}{l}{\textbf{Total}} \\") postfoot("\midrule \end{tabular}") prefoot("") prehead("[1em]")
end


use "${datadir}cip_all_both.dta", clear

gen cip_rf = (r - r_usd - rho)*100
gen con = 1

egen curr_group = group(currency)
egen tenor_group = group(tenor)
egen panel_id = group(curr_group tenor_group)

bcal create sp500, from(date) replace
gen bdate = bofd("sp500", date)

summstats cip_govt
summstats cip_rf
